package com.base.controller;

import lombok.extern.slf4j.Slf4j;
import com.base.utils.LogUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LogController {
    /**
     * 测试日志等级
     *
     * @return
     */
    @RequestMapping("/loglevel")
    public String logLevel() {
        log.debug("debug log");
        log.info("info log");
        log.error("error log");
        return "success";
    }

    /**
     * 设置日志等级
     *
     * @param level
     * @return
     */
    @RequestMapping("/changeLog/{level}")
    public String changeLevel(@PathVariable String level) {
        if (!StringUtils.isEmpty(level)) {
            LogUtil.setAllLogLevel(level);
        }
        return "change log level success, level:" + level;
    }
}